package com.lucy.management.utils;


import com.alibaba.fastjson.JSON;

import java.io.Serializable;

/**
 * 返回结果
 * 状态码
 * 信息
 * 数据
 *
 * @author
 */
public class AjaxResult implements Serializable {

    //消息提醒
    public static final String SUCCESS = "操作成功";
    public static final String FAIL = "操作失败";
    public static final String ERROR = "操作错误";

    private boolean flag;
    private String msg;
    private Object data;
    private Integer code;

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public AjaxResult() {
    }

    public AjaxResult(Object data) {
        this.data = data;
        this.flag = true;
        this.msg = SUCCESS;
        this.code = 200;
    }


    public AjaxResult(String msg) {
        this.msg = msg;
        this.data = null;
        this.flag = false;
        this.code = 510;
    }

    public AjaxResult(boolean flag, String msg, Object data) {
        this.flag = flag;
        this.msg = msg;
        this.data = data;
        this.code = flag ? 200 : 510;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }


    public static AjaxResult success(Object data) {
        return new AjaxResult(data);
    }

    public static AjaxResult success(String msg, Object data) {
        return new AjaxResult(true, msg, data);
    }

    public static AjaxResult fail(String msg) {
        return new AjaxResult(msg);
    }


}
